define('ajaxErrorTips', function(ajaxErrorTips) {
    // checkbox
    var UploadInput = function(config) {
        var uploadInput = this;
        require(['js/assets/jquery.fileupload'], function() {
            uploadInput.$dom = config.$dom

            var options = {
                autoUpload: true,
                send: function (e, data) {
                  _Waiting.show();
                },
                progressall: function(e, data) {
                    // var progress = parseInt(data.loaded / data.total * 100, 10);
                    // _Waiting.show(undefined, progress + '%');
                },
                always: function(e, data) {
                    _Waiting.close();
                },
                done: function(e, data) {
                    var resultData = data.result;
                    switch (resultData.status.code) {
                        case 0:
                            config.done && config.done(resultData.data);
                            break;
                        default:
                            _Alert('数据有误', resultData.status.message + '(No.' + resultData.status.code + ')');
                    }
                    _Waiting.close();
                },
                fail: function(e, data) {
                    ajaxErrorTips({
                        From: config.url,
                        RequestStatus: data.textStatus,
                        RequestStatusText: data.errorThrown
                    });
                    config.fail && config.fail(e, data);
                }
            }

            if(config.formData) {
              $.extend(options, { formData: config.formData })
            }

            uploadInput.$dom.fileupload(options);
            if (typeof config.init === 'function') {
                config.init(uploadInput.$dom);
            }
        });
    }
    window.UploadInput = UploadInput;
    return UploadInput;
})
